/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Disposable Object Collection Class
 *      Provides a custom collection implementation for storing 
 * DisposableObject instances.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using Adaptive.Foundation;

namespace Adaptive.Foundation.Collections
{
    /// <summary>
    /// Provides a custom collection implementation for storing 
    /// <see cref="DisposableObjectBase"/> instances.
    /// </summary>
    public class DisposableObjectCollection : GenericCollectionBase<DisposableObjectBase>
    {  
        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <value>
        /// This is the default constructor.
        /// </value>
        public DisposableObjectCollection() : base()
        {
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Methods / Functions
         *------------------------------------------------------------------------------*/
        #region Public Methods / Functions
        /// <summary>
        /// Gets the unique key for the specified object instance used to idemn
        /// </summary>
        /// <param name="itemToGetKeyFor">The object being appended to the collection.</param>
        /// <returns>
        /// A string value used to identify the object instance.
        /// </returns>
        protected override string GetKeyForObject(DisposableObjectBase itemToGetKeyFor)
        {
            string returnValue = string.Empty;              //Return value.

            if (itemToGetKeyFor != null)
            {
                if (itemToGetKeyFor.GetType() == typeof(INamedInstance))
                    returnValue = ((INamedInstance)itemToGetKeyFor).Name;
                else
                    returnValue = Count.ToString();
            }
            return returnValue;
            
        }
        #endregion
    }
}
